<?php

// bkt_view.php
// Michael Baker
// 2010.07.15
//
// View bracket in detail

session_start();

define("IN_MDM", true);
define("CUR_PAGE_TITLE", "View bracket");
define("CUR_FLAG", "bkt.view");

include '../includes/all.php';
include 'inc/header.php';

if ( !( array_key_exists( "id", $_GET ) && is_numeric( $_GET["id"] ) ) )
{
  echo ui_error( "No bracket ID supplied" );
  include 'inc/footer.php';
  die;  
}

$id = $_GET["id"];
$categories = $dbase->get_thresholding_categories();

if ( !array_key_exists( $id, $categories ) ) 
{
  echo ui_error( "Bracket $id not found" );
  include 'inc/footer.php';
  die;
}

?>

<table class="type2p" cellspacing="1">
  <caption><?php echo "#$id: " . $categories[$id]; ?></caption>
  <col class="col1" /><col class="col2" />
  
  <thead>
    <tr>
      <th>Property</th>
      <th>Value</th>
    </tr>
  </thead>
  
  <tbody>
    <tr>
      <td>Bracket Title:</td>
      <td><?php echo $categories[$id]; ?></td>
    </tr>
    
    <tr>
      <td>Map Color:</td>
      <td><?php echo $dbase->get_thresholding_mapcolor($id); ?></td>
    </tr>
    
    <tr>
      <td>Segments:</td>
      <td><?php echo count( $dbase->get_nodecouples_by_category($id) ); ?></td>
    </tr>
    
  </tbody>
</table>
<br />
<?php

$f_names = array( "Loss (frames per sample)", "R. Delay (seconds)" );

$ctr = 0;
while ( $ctr < count($f_names) )
{
  $f_name = $f_names[ $ctr ];
  
  $fault_id = $ctr;
  echo "<table class=\"type2p\" cellspacing=\"1\">\n";
  echo "<caption>$f_name</caption>";
  echo str_repeat( "<col class=\"col1\" />", 3 );
  echo "<thead>\n";
  echo "<tr>\n";
  echo "<th>Colour</th>\n";
  echo "<th>Lower bound</th>\n";
  echo "<th>Upper bound</th>\n";
  echo "</tr>\n";
  echo "</thead>\n";
  
  echo "<tbody>\n";
  $data = $dbase->get_thresholds( $id, $ctr );
  foreach ( $data as $row )
  {
    $floor = $row[ 0 ]; $ceil = $row[ 1 ];
    $floorh = $row[ 2 ]; $ceilh = $row[ 3 ];
    $ceili = $row[ 4 ]; $cc = $row[ 5 ];
    
    $cc_tup = $dbase->get_colorcode( $cc );
    $td_tag = "<td style=\"background-color: rgb(" . implode(",", $cc_tup) . ");\">";
    
    echo "<tr>\n";
    echo $td_tag . "&nbsp;</td>\n";
    echo "<td>" . ($floorh ? "<strong>$floor</strong>" : $floor) . "</td>\n";
    echo "<td>" . ($ceili ? "&infin;" : ($ceilh ? "<strong>$ceil</strong>" : $ceil)) . "</td>\n";
    echo "</tr>\n";
  }
  
  echo "</tbody>\n";
  echo "</table>\n";
  echo "<br />";
  $ctr++;
}

include 'inc/footer.php';

?>